var SortableTableHeader = new Class({
	Implements: Options,
	
	selected:null,
	selected_count:0,
	el_header: [],
	
	options:{
		/**
		 * a listener when header click
		 * @param item - the header element
		 * @param tableFieldName - the field name on table
		 */
		onHeaderClick:$empty,
		
		/**
		 * array of field name on table
		 */
		tableFieldName:[],
		
		sort:['asc', 'desc'],
	},
	
	initialize: function(tableRow, option){
		this.el_header = tableRow.getElements('td');
		this.setOptions(option).attach();
	},
	
	attach: function(){
		this.el_header.each(function(item, index){
			item.addEvent('click', function(){
				if (this.options.onHeaderClick){
					var sorting_method = "";
					if (this.selected==item){
						sorting_method = this.options.sort[++this.selected_count % 2];
					}
					else{
						this.selected = item;
						this.selected_count = 0;
						sorting_method = this.options.sort[this.selected_count];
					}
					this.options.onHeaderClick(item, this.options.tableFieldName[index], sorting_method);
				}
			}.bind(this))
			.setStyle('cursor','pointer');
		}.bind(this));
	}
});